#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
int n;
list<int> edges[102];
bool visit[102];
LL w[102];
LL cur=0;
queue<pair<int,int>> que;

int main(){
	cin>>n;
	int left,right;
	for(int i=1;i<=n;i++){
		cin>>w[i]>>left>>right;
		if(left!=0){
			edges[i].push_back(left);
			edges[left].push_back(i);
		}
		if(right!=0){
			edges[i].push_back(right);
			edges[right].push_back(i);			
		}
	}
	LL ans=LLONG_MAX;
	for(int i=1;i<=n;i++){
		memset(visit,false,sizeof(visit));
		visit[i]=true;
		que.push(make_pair(i,0));
		cur=0;
		while(!que.empty()){
			int a=que.front().first;
			int len=que.front().second;
			que.pop();
			for(auto j:edges[a]){
				if(!visit[j]){
					//cout<<j<<' '<<(len+1)<<'*'<<w[j]<<endl;
					cur+=(len+1)*w[j];
					que.push(make_pair(j,len+1));
					visit[j]=true;
				}
			}
		}
		ans=min(cur,ans);
		//cout<<cur<<endl;
	}
	cout<<ans;
	return 0;
}
